<!--
 * 配置管理
 * @author luguoxiang
 * @date 2023-03-27
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
-->
<template>
  <t-form ref="form" :data="model" :colon="true" label-width="12em">
    <t-form-item label="登录验证码" name="captcha">
      <t-switch v-model="model.captcha" :label="['启用', '禁用']" />
    </t-form-item>
    <t-form-item label="最多允许错误次数" name="maxFailCount">
      <t-input-number
        v-model="model.maxFailCount"
        placeholder="最多允许错误次数，超过账号将长期锁定，需管理员解锁"
        :max="255"
        :min="0"
        theme="column"
      />
    </t-form-item>
    <t-form-item label="首次密码错误允许次数" name="firstFailCount">
      <t-input-number
        v-model="model.firstFailCount"
        placeholder="首次密码错误允许次数，超过将短期锁定"
        :max="model.maxFailCount"
        :min="0"
        theme="column"
      />
    </t-form-item>
    <t-form-item label="密码错误锁定时长(秒)" name="failInterval">
      <t-input-number v-model="model.failInterval" placeholder="密码错误锁定时长" theme="column" step="60" :min="0" />
      <span style="padding-left: var(--app-space-horizontal)"> {{ durationFormat(model.failInterval) }}</span>
    </t-form-item>
  </t-form>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { durationFormat } from '@/soar';
import api from '@/api/sysConfig';

const code = 'login';
const model = ref({});
const form = ref();

function load() {
  api.get(code).then((res) => {
    model.value = res ?? {};
  });
}

defineExpose({
  submit() {
    form.value.validate().then(() => {
      api.set(code, model.value);
    });
  },
  reset() {
    return form.value.reset();
  },
});

onMounted(() => {
  load();
});
</script>
